package ch07;
import com.ktjy.dao.sysUser.service.SysUserService;
import com.ktjy.pojo.SysUser;
import org.apache.log4j.Logger;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;


import java.util.*;

public class SysUserTest {

    private Logger logger = Logger.getLogger(String.valueOf(SysUserTest.class));  // 修改获取 Logger 的方式

    @Before
    public void setUp() throws Exception {

    }
        @Test
        public void testGetUserList() {
                ApplicationContext cts = new ClassPathXmlApplicationContext("ch07/sl.xml");
                SysUserService userService = (SysUserService) cts.getBean("userService");
                List<SysUser> userList = new ArrayList<>();  // 简化泛型声明
                SysUser userCondition = new SysUser();
                userCondition.setRealName("赵");
                userCondition.setRoleId(2);
                userList = userService.getList(userCondition);
                for (SysUser userResult : userList) {
                    logger.debug("testGetUserList account:"+userResult.getAccount()+"and realName"+userResult.getRealName()+"and roleId:"
                    +userResult.getRoleId()+"and roleName:"+userResult.getRoleIdName()+"and address:"+userResult.getAddress());  // 补充输出的具体内容
                }
            }
            @Test
            public void testAddUser()throws Exception{
                ApplicationContext cts = new ClassPathXmlApplicationContext("ch07/sl.xml");
                SysUserService userService = (SysUserService) cts.getBean("userService");
                SysUser user=new SysUser();
                user.setId(1);
                user.setAccount("user123");
                user.setRealName("张三");
                user.setPassword("123456");
                user.setSex(1);
                user.setPhone("123456789");
                user.setAddress("北京市朝阳区");
                user.setRoleId(2);
                user.setCreateUserId(10);
                user.setCreateTime(new Date());
                user.setUpdateUserId(11);
                user.setUpdateTime(new Date());
                user.setAge(25);
                user.setRoleIdName("管理员");
                boolean result = userService.add(user);
                logger.debug("testAdd result:"+result);
            }
}

